/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.apache.hadoop.contrib.mfs;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;


/**
 *
 * @author eces
 */
public class FileSystemLauncher {


    public static void main(String args[]){
        MetadataManager manager;

        try {
            configure(args);
            manager = MetadataManager.getInstance();

            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String input;


            while(true){
                input = reader.readLine();
                String command[] = input.split(" ");

                if(command[0].equals("add")){

                }else if(command[0].equals("delete")){
                    
                }
            }
        } catch (Exception ex) {
            System.err.println(ex.getMessage());
        }

    }
    public static void configure(String args[]) throws Exception{
        // Default Settings
        MfsConfiguration.config.setProperty("mfs.storage.totalSize", Integer.toString(1024*1024*1024));
        MfsConfiguration.config.setProperty("mfs.storage.chunkSize", Integer.toString(1024*1024*4));

        if(args.length < 1){
            throw new Exception("Usage: FileSystemLauncher config_path[, totalStroageSize, chunkSize]");
        }
        for (int i = 0; i < args.length; ++i) {
            if ("-config".equals(args[i])) {
                // Required
                MfsConfiguration.config.setProperty("mfs.config.path", args[++i]);
                MfsConfiguration.config.load(new FileInputStream(args[i]));
            } else if("-totalStorageSize".equals(args[i])){
                // Optional
                MfsConfiguration.config.setProperty("mfs.storage.totalSize", Integer.toString(1024*1024*1024));
            } else if("-chunkSize".equals(args[i])){
                // Optional
                MfsConfiguration.config.setProperty("mfs.storage.chunkSize", Integer.toString(1024*1024*4));
            }
        }
    }

}
